from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-24 14:04:07.921931
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 24, Jan, 2022
Time: 14:04:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.8236
Nobs: 546.000 HQIC: -48.2556
Log likelihood: 6366.81 FPE: 8.36498e-22
AIC: -48.5329 Det(Omega_mle): 7.10437e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.355488 0.070039 5.076 0.000
L1.Burgenland 0.105871 0.042555 2.488 0.013
L1.Kärnten -0.112528 0.022055 -5.102 0.000
L1.Niederösterreich 0.191178 0.088803 2.153 0.031
L1.Oberösterreich 0.129204 0.087721 1.473 0.141
L1.Salzburg 0.258464 0.044937 5.752 0.000
L1.Steiermark 0.030330 0.059300 0.511 0.609
L1.Tirol 0.102747 0.047826 2.148 0.032
L1.Vorarlberg -0.073141 0.042267 -1.730 0.084
L1.Wien 0.019403 0.078034 0.249 0.804
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059015 0.152298 0.387 0.698
L1.Burgenland -0.042444 0.092536 -0.459 0.646
L1.Kärnten 0.040647 0.047958 0.848 0.397
L1.Niederösterreich -0.205670 0.193102 -1.065 0.287
L1.Oberösterreich 0.456058 0.190749 2.391 0.017
L1.Salzburg 0.284162 0.097716 2.908 0.004
L1.Steiermark 0.114165 0.128948 0.885 0.376
L1.Tirol 0.305729 0.103998 2.940 0.003
L1.Vorarlberg 0.021471 0.091910 0.234 0.815
L1.Wien -0.023750 0.169683 -0.140 0.889
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.196535 0.035680 5.508 0.000
L1.Burgenland 0.090658 0.021679 4.182 0.000
L1.Kärnten -0.007356 0.011235 -0.655 0.513
L1.Niederösterreich 0.235576 0.045239 5.207 0.000
L1.Oberösterreich 0.168779 0.044688 3.777 0.000
L1.Salzburg 0.038783 0.022893 1.694 0.090
L1.Steiermark 0.024760 0.030209 0.820 0.412
L1.Tirol 0.081015 0.024364 3.325 0.001
L1.Vorarlberg 0.054800 0.021532 2.545 0.011
L1.Wien 0.118114 0.039753 2.971 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118391 0.035863 3.301 0.001
L1.Burgenland 0.043569 0.021790 1.999 0.046
L1.Kärnten -0.013874 0.011293 -1.229 0.219
L1.Niederösterreich 0.172433 0.045471 3.792 0.000
L1.Oberösterreich 0.336192 0.044917 7.485 0.000
L1.Salzburg 0.099804 0.023010 4.337 0.000
L1.Steiermark 0.109140 0.030364 3.594 0.000
L1.Tirol 0.090517 0.024489 3.696 0.000
L1.Vorarlberg 0.059581 0.021643 2.753 0.006
L1.Wien -0.016050 0.039957 -0.402 0.688
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.122200 0.067703 1.805 0.071
L1.Burgenland -0.045968 0.041136 -1.117 0.264
L1.Kärnten -0.045382 0.021319 -2.129 0.033
L1.Niederösterreich 0.141359 0.085841 1.647 0.100
L1.Oberösterreich 0.167605 0.084795 1.977 0.048
L1.Salzburg 0.282400 0.043439 6.501 0.000
L1.Steiermark 0.060623 0.057322 1.058 0.290
L1.Tirol 0.154478 0.046231 3.341 0.001
L1.Vorarlberg 0.094441 0.040857 2.311 0.021
L1.Wien 0.071898 0.075431 0.953 0.341
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.085093 0.052717 1.614 0.106
L1.Burgenland 0.021617 0.032031 0.675 0.500
L1.Kärnten 0.053061 0.016600 3.196 0.001
L1.Niederösterreich 0.191009 0.066841 2.858 0.004
L1.Oberösterreich 0.329241 0.066027 4.986 0.000
L1.Salzburg 0.035360 0.033824 1.045 0.296
L1.Steiermark 0.000585 0.044635 0.013 0.990
L1.Tirol 0.121311 0.035998 3.370 0.001
L1.Vorarlberg 0.065537 0.031814 2.060 0.039
L1.Wien 0.098735 0.058735 1.681 0.093
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172642 0.063802 2.706 0.007
L1.Burgenland 0.005384 0.038766 0.139 0.890
L1.Kärnten -0.065244 0.020091 -3.247 0.001
L1.Niederösterreich -0.108592 0.080896 -1.342 0.179
L1.Oberösterreich 0.215843 0.079910 2.701 0.007
L1.Salzburg 0.052072 0.040936 1.272 0.203
L1.Steiermark 0.251223 0.054020 4.651 0.000
L1.Tirol 0.497581 0.043568 11.421 0.000
L1.Vorarlberg 0.065154 0.038504 1.692 0.091
L1.Wien -0.082247 0.071085 -1.157 0.247
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160359 0.070560 2.273 0.023
L1.Burgenland -0.007511 0.042872 -0.175 0.861
L1.Kärnten 0.062410 0.022219 2.809 0.005
L1.Niederösterreich 0.178672 0.089464 1.997 0.046
L1.Oberösterreich -0.065649 0.088374 -0.743 0.458
L1.Salzburg 0.206156 0.045272 4.554 0.000
L1.Steiermark 0.136608 0.059742 2.287 0.022
L1.Tirol 0.056534 0.048182 1.173 0.241
L1.Vorarlberg 0.143972 0.042582 3.381 0.001
L1.Wien 0.131600 0.078614 1.674 0.094
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.394068 0.041208 9.563 0.000
L1.Burgenland -0.002911 0.025038 -0.116 0.907
L1.Kärnten -0.020425 0.012976 -1.574 0.115
L1.Niederösterreich 0.203557 0.052248 3.896 0.000
L1.Oberösterreich 0.241915 0.051611 4.687 0.000
L1.Salzburg 0.033023 0.026439 1.249 0.212
L1.Steiermark -0.017006 0.034890 -0.487 0.626
L1.Tirol 0.086457 0.028139 3.073 0.002
L1.Vorarlberg 0.051436 0.024868 2.068 0.039
L1.Wien 0.033635 0.045911 0.733 0.464
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.034995 0.101810 0.167224 0.134802 0.091571 0.081527 0.030636 0.213195
Kärnten 0.034995 1.000000 -0.026543 0.133076 0.047415 0.084835 0.445523 -0.069397 0.093494
Niederösterreich 0.101810 -0.026543 1.000000 0.308932 0.126019 0.266763 0.067530 0.156654 0.281629
Oberösterreich 0.167224 0.133076 0.308932 1.000000 0.215858 0.293240 0.170373 0.135278 0.235497
Salzburg 0.134802 0.047415 0.126019 0.215858 1.000000 0.126935 0.088476 0.105393 0.127264
Steiermark 0.091571 0.084835 0.266763 0.293240 0.126935 1.000000 0.136153 0.103373 0.030598
Tirol 0.081527 0.445523 0.067530 0.170373 0.088476 0.136153 1.000000 0.064918 0.150167
Vorarlberg 0.030636 -0.069397 0.156654 0.135278 0.105393 0.103373 0.064918 1.000000 -0.004938
Wien 0.213195 0.093494 0.281629 0.235497 0.127264 0.030598 0.150167 -0.004938 1.000000